package com.resume.aipeople.config;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;

import javax.annotation.PostConstruct;

/**
 * Gemini配置类
 * 负责设置Gemini API相关的环境变量
 */
@Configuration
@Slf4j
public class GeminiConfig {

    @Value("${gemini.api.key:${GEMINI_API_KEY:}}")
    private String geminiApiKey;
    
    @Value("${google.api.key:${GOOGLE_API_KEY:}}")
    private String googleApiKey;

    @PostConstruct
    public void setupGeminiEnvironment() {
        // 优先使用googleApiKey，如果没有则使用geminiApiKey
        String apiKey = (googleApiKey != null && !googleApiKey.trim().isEmpty()) ? 
                       googleApiKey : geminiApiKey;
        
        if (apiKey != null && !apiKey.trim().isEmpty()) {
            // 设置系统属性作为备用方案
            System.setProperty("GOOGLE_API_KEY", apiKey);
            log.info("Gemini API Key配置完成，API Key: {}...", 
                    apiKey.length() > 10 ? apiKey.substring(0, 10) : "null");
        } else {
            log.warn("Gemini API Key未配置，Gemini模型将不可用");
        }
    }
}
